#
# Makefile for NewLife kernel
#
export CC := i386-elf-g++ -fno-exceptions -g -c
export AS := nasm -f elf
export LD := i386-elf-ld
MAKE := make

## CONFIGURATION
# Directory of include file
export INC_DIR := ../include
CC += -I $(INC_DIR)/
AS += -I $(INC_DIR)/asm-inc/
# Directory of intermedia/object file
export OBJ_DIR := /usr/obj/forever043/NewLife/kernel
export VPATH := $(INC_DIR):$(OBJ_DIR)

TARGET = $(OBJ_DIR)/nfknl.bin
KNL_OBJ = $(OBJ_DIR)/boot.o		\
          $(OBJ_DIR)/core.o		\
          $(OBJ_DIR)/misc.o		\
          $(OBJ_DIR)/pageman.o		\
          $(OBJ_DIR)/intrman.o		\
          $(OBJ_DIR)/schedule.o		\
          $(OBJ_DIR)/moduleman.o

all : $(TARGET)

$(TARGET) : $(KNL_OBJ) linker.ld
	@echo Linking kernel ....
	$(LD) -T linker.ld -o $@ $(KNL_OBJ) -lc


$(OBJ_DIR)/boot.o : boot/*
	@echo Build BOOT module ....
	@$(MAKE) -C boot
	
$(OBJ_DIR)/misc.o : misc/*
	@echo Build MISC module ....
	@$(MAKE) -C misc

$(OBJ_DIR)/core.o : core/*
	@echo Build CORE module ....
	@$(MAKE) -C core

$(OBJ_DIR)/pageman.o : pageman/*
	@echo Build Page Manage module ....
	@$(MAKE) -C pageman 

$(OBJ_DIR)/intrman.o : intrman/*
	@echo Build Interrupt Manage module ....
	@$(MAKE) -C intrman

$(OBJ_DIR)/schedule.o : schedule/*
	@echo Build Schedule module ....
	@$(MAKE) -C schedule

$(OBJ_DIR)/moduleman.o : moduleman/*
	@echo Build Module manager module ....
	@$(MAKE) -C moduleman

rebuild : clean all

tar :

install :
	cp $(TARGET) /usr/home/NewLife/boot/ 

clean :
	- rm $(OBJ_DIR)/*.o
	- rm $(OBJ_DIR)/*.bin

.PHONY : all tar clean rebuild install
